#encoding=utf-8
'''
Created on 2018-8-9

@author: cooler
'''
import sys, logging, os, os.path
sys.path.append(os.getcwd()+"/utils" )

from Config import initConfig
config = initConfig()

from flask import Flask
#------------app interface-------------------
from service.home import home as home_blue
from service.auth import user as user_blueprint
from service.trade import trade as trade_blue



# from models import mdb
import random

DEFAULT_APP_NAME = 'SUFACE'


DEFAULT_MODULES = (
    (home_blue, '/home'),
    (user_blueprint, '/user'),
    (trade_blue, '/trade'),
)

def setting_modules(app, modules):
    """ 注册Blueprint模块 """
    for module, url_prefix in modules:
        # 通过register_blueprint注册
        app.register_blueprint(module, url_prefix = url_prefix)

def create_app():
    """ 创建、初始化app """
    app = Flask(DEFAULT_APP_NAME)
    # 使用flask中的Blueprint设置站点模块
    setting_modules(app, DEFAULT_MODULES)
    # host = config.get("mongo","host")
    # port = int(config.get("mongo","port"))
    # username = config.get("mongo","username")
    # password = config.get("mongo","password")
    # dbname = config.get("mongo","dbname")
    # app.config['MONGODB_DB'] = 'suface'
    # app.config['MONGODB_HOST'] = '127.0.0.1'
    # app.config['MONGODB_PORT'] = 27017
    # app.config['MONGODB_USERNAME'] = ''
    # app.config['MONGODB_PASSWORD'] = ''
    # mdb.init_app(app)   
    return app


        